package com.xhdx.threadpool;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@SuppressWarnings({"rawtypes","unchecked"})
public class FutureTest {
    public static void main(String[] args) {
        ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
        Future future = singleThreadExecutor.submit(new Runnable() {
            @Override
            public void run() {  
                System.out.println("Asynchronous task"); 
            }  
        });
        //如果任务结束执行则返回 null  
        try {
            System.out.println("future.get()=" + future.get());
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        future = singleThreadExecutor.submit(new Callable(){  
            public Object call() throws Exception {  
                System.out.println("Asynchronous Callable");  
                return "Call Result";  
            }  
        });  
          
        try {
            System.out.println("future.get() = " + future.get());
        }  catch (Exception e) {
            e.printStackTrace();
        }

    }
}
